<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/26 0026
 * Time: 下午 5:18
 */
namespace app\common\model;


class Order extends BaseModel {
    protected $autoWriteTimestamp = true;
//订单状态 1=待付款， 2=待发货，3=待收货，4=已完成，5=已失效，6=售后，7=已消费，8=未消费，9=拼团中，10=同意售后退款，11=拒绝售后退款

    const STATUS_1 = 1;  //待付款
    const STATUS_PENDING_DELIVERY = 2;  //待发货
    const STATUS_3 = 3;  //待收货
    const STATUS_4 = 4;  //已完成
    const STATUS_5 = 5;  //已失效
    const STATUS_6 = 6;  //售后
    const STATUS_7 = 7;  //未消费
    const STATUS_8 = 8;  //拼团中
    const STATUS_9 = 9;  //同意售后退款
    const STATUS_10 = 10;  //拒绝售后退款
    const STATUS_11 = 11;  //待发货
    const STATUS_12 = 12;  //待接单
    const STATUS_13 = 13;  //订单已取消
    const TYPE_0 = 0;//类型  0=线上订单 1=线下订单
    const TYPE_1 = 1;
//配送方式   0=物流配送  1=自行配送 2=达达配送 3=到店自取
    const DELIVERMETHOD_0 = 0;
    const DELIVERMETHOD_1 = 1;
    const DELIVERMETHOD_2 = 2;
    const DELIVERMETHOD_3 = 3;


    public function orderproductDetail(){
        return $this->hasMany('orderproductdetail','orderId','id');
    }


    public function getCurrentOrder($id){
    return self::where("id","=",$id)->find();
    }

   // public function getOrderNoCurrentOrder($orderNo,$uid){
        public function getOrderNoCurrentOrder($orderNo){

        return self::where([
          "orderNO"=>$orderNo,
         // "createUser"=>$uid
            ])->find();
    }


    /**
     * @param $data
     */
    public function addIntegralOrder($data){
        return self::save($data);
    }

    /**
     *
     */
    public function findOrder($orderNO){
        return self::where('orderNO','=',$orderNO)->find();
    }


    public function updateOrderStatus($orderParam){
        return self::where(['id'=>$orderParam['orderId']])->update(['status'=>$orderParam['status']]);
    }

}